#ifdef LCD_I2C
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);  // set the LCD address to 0x27 for a 16 chars and 2 line display

void UserPlugin_LCD_Init(void)
{
  lcd.init();                      // initialize the lcd 
  lcd.backlight();
  lcd.clear();
  lcdprintline(0,"Nodo Domotica");

  TempString[0]=0;

#if NODO_MEGA
  sprintf(TempString,"Mega R:%03d U:%d", NODO_BUILD, Settings.Unit);
#else
  #ifdef NODO_CLASSIC
    sprintf(TempString,"Classic", NODO_BUILD, Settings.Unit);
  #else
    sprintf(TempString,"Small R:%03d U:%d", NODO_BUILD, Settings.Unit);
  #endif
#endif
lcdprintline(1,TempString);

}

/*********************************************************************************************\
 * print line to LCD at given row
 \*********************************************************************************************/

void lcdprintline(byte row, char* message) {

  lcd.setCursor(0,row);
  lcd.print("                ");
  lcd.setCursor(0,row);
  lcd.print(message);
}

/*********************************************************************************************\
 * print line to LCD with wrap to next line
 \*********************************************************************************************/

void lcdprint(char* text)
{
  byte column=0;
  byte line=0;
  byte character;
  byte x=0;

  lcd.clear();

  for (x=0; x < 33; x++) {
    character = text[x];
    if (character == 0) break;
    if (column >= 16) {
      column=0;
      line=1;
    }

    if( character == 10) {
      column=0;
      line=1;
    }
    else
    {
      if( character != 13) {
        lcd.setCursor(column,line);
        lcd.write(character);
        column++;
      }
    }
  }
}
#endif

